//== GAIA ============================================================================

//== BEGINNING OF CODE ===============================================================

#include "sagittarius/core/SagittariusCore.h"
#include "sagittarius/parallel/thread.h"
#include "sagittarius/io/io.h"
#include <windows.h>

long create_thread(void (*thread_func)(void*), void* param);
void exit_thread(long result);

void target(void* arg) {
    sg_write(2, "target was run\n", sizeof("target was run\n"));
    //exit_thread(0);
    //return 0;
}

int main(int argc, char* argv[])
{
    spawnresult res;
    HANDLE hTimer = NULL;
    LARGE_INTEGER t;
    //timer
    t.QuadPart = -10000000LL;
    hTimer = CreateWaitableTimer(NULL, TRUE, NULL);
    
    res = sg_spawn(target, NULL);
    if(!spawn_successful(res)) {
        SG_WRITE(2, "Error creating process");
        AN(0);
    }
    
    AT(SetWaitableTimer(hTimer, &t, 0, NULL, NULL, 0));
    //sleep for 1sec
    AT(WaitForSingleObject(hTimer, INFINITE) == WAIT_OBJECT_0);
    sg_write(2, "sleep finished\n", sizeof("sleep finished\n"));
    
    return 0;
}
